#!/usr/bin/env node
import { Command } from 'commander'
import { readFileSync, writeFileSync } from 'fs'
import path from 'path'

const program = new Command()

program
  .option('-n --name <name>', '命令名称')
  .option('-d --desc <desc>', '帮助信息')

program.parse(process.argv)

interface Options {
  name: string
  desc: string
}

// 模拟顶层 await
void (async () => {
  const { name, desc }: Options = program.opts()
  if (name === undefined || desc === undefined) {
    throw new Error('name desc 都是必填项')
  }
  const filePath = path.join(`./src/script/hc-${name}.ts`)
  const newscript = readFileSync('./temp/newscript.text')
  const data = new Uint8Array(Buffer.from(newscript))
  writeFileSync(filePath, data)
})()
